# -*- coding: utf-8 -*-
# @Time    : 2024/8/10 12:37
# @Author  : SunTianXu
# @Email   : xjsuntianxu@163.com
# @File    : RequestUtils.py
# @Software: PyCharm
import requests
import urllib3

# 关闭警告信息
urllib3.disable_warnings()


def send_post(url, headers, data, file):
    """
    发送POST请求
    :param url: 请求的URL
    :param headers: 请求头
    :param data: 请求体
    :return: 响应对象
    """
    if file:
        return requests.post(url=url, headers=headers, data=data, files=file, verify=False)
    else:
        return requests.post(url=url, headers=headers, data=data, verify=False)


def send_get(url, headers):
    """
    发送GET请求
    :param url: 请求的URL
    :param headers: 请求头
    :return: 响应对象
    """
    return requests.get(url=url, headers=headers, verify=False)


def send_path(url, headers, data):
    """
    发送PATCH请求
    :param url: 请求的URL
    :param headers: 请求头
    :param data: 请求体
    :return: 响应对象
    """
    return requests.patch(url=url, headers=headers, data=data, verify=False)


def send_delete(url, headers):
    """
    发送DELETE请求
    :param url: 请求的URL
    :param headers: 请求头
    :return: 响应对象
    """
    return requests.delete(url=url, headers=headers, verify=False)


def create_general_headers(auth_token: str = None, e_tag: str = None):
    """
    创建通用的请求头
    :param auth_token: 认证令牌
    :param e_tag: 实体标签
    :return: 包含通用请求头的字典
    """
    if e_tag is not None or e_tag != '':
        return {"Cache-Control": "no-cache", "X-Auth-Token": auth_token, "Content-Type": "application/json",
                "if-Match": e_tag}
    if auth_token is not None or auth_token != '':
        return {"Cache-Control": "no-cache", "X-Auth-Token": auth_token}
    return {"Cache-Control": "no-cache"}
